package org.jb.coinche.client.business.model;

import java.io.Serializable;

/**
 * 
 * @author jeremie
 *
 */
public class Card implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 591936618938681258L;
	/**
	 * 
	 * @author jeremie
	 *
	 */
	public enum Color {
		CLUBS,
		DIAMONDS,
		SPADES,
		HEARTS;

		// TODO : Reussir à faire fonctionner la SimpleComboBox avec un PropertyEditor ...
		public String toText() {
			switch( this ) {
			case CLUBS: return "Trèfles";
			case DIAMONDS: return "Carreaux";
			case HEARTS: return "Coeurs";
			case SPADES: return "Piques";
			default:
				return "";
			}
		}

		// TODO : Reussir à faire fonctionner la SimpleComboBox avec un PropertyEditor ...
		public static Color fromText(String value) {
			if ("Trèfles".equals(value))
				return CLUBS;
			else if ("Carreaux".equals(value))
				return DIAMONDS;
			else if ("Coeurs".equals( value ))
				return HEARTS;
			else if ("Piques".equals( value ))
				return SPADES;
			return null;
		}
	}
	
	
	/**
	 * 
	 * @author jeremie
	 *
	 */
	public enum Value {
		KING,
		QUEEN,
		JACK,
		TEN,
		NINE,
		EIGHT,
		SEVEN,
		AS
	}
	
	/*
	 * 
	 */
	public Card() {
		this.color = null;
		this.value = null;
	}
	
	/*
	 * 
	 */
	public Card(Color color, Value value) {
		this.color = color;
		this.value = value;
	}

	/**
	 * 
	 * @return
	 */
	public Color getColor() {
		return color;
	}
	
	/**
	 * 
	 * @param color
	 */
	public void setColor( Color color ) {
		this.color = color;
	}
	
	/**
	 * 
	 * @return
	 */
	public Value getValue() {
		return value;
	}
	
	/**
	 * 
	 * @param value
	 */
	public void setValue( Value value ) {
		this.value = value;
	}
	
	
	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Card) {
			Card c = (Card)obj;
			return color.equals( c.getColor() ) && value.equals( c.getValue() );
		}
		return false;
	}

	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append( value );
		sb.append( '@' );
		sb.append( color );
		return sb.toString();
	}



	private Color color;
	private Value value;
}
